/**
 * Created by jiangtao on 2017/5/27.
 */

import types from './../../const/home';

var initState = {
    dataList:[],
    dataDetail:{},
    tabs:[
        {name:"全部", category : "" , active:true},
        {name:"精华", category :"good" },
        {name:"分享", category :"share" },
        {name:"问答", category :"ask" },
        {name:"招聘", category :"job" }
    ]
}

export default function( state = initState , action ){
    const type = action.type;
    let copyState = Object.assign( {} , state );
    switch ( type ) {
        case types.GET_LIST : copyState.dataList = action.data;break;
        case types.GET_DETAIL : copyState.dataDetail = action.data;break
        case types.CHANGE_TAB :
            copyState.tabs = copyState.tabs.map(( val , index )=>{
                index == action.data ? val.active = true : val.active = false;
                return val;
            });break;
    }

    return copyState
}
